package cc.wsyw126.java.jvm;

/**
 * Created by junpeng.yang on 17/3/11.
 */
public class ImplementsAutoCloseable {

    private static class Test implements AutoCloseable {

        @Override
        public void close() throws Exception {
            System.out.println("true = " + true);
            throw new Exception("throws exception");
            //这里主要是为了验证在关闭时抛出异常被谁捕获而写的代码
        }

        public void test() throws Exception {
            throw new Exception("调用时出异常，看是否调用close方法!");
        }
    }

    public static void main(String[] args) {
        try (Test test = new Test()) {
            test.test();
        } catch (Throwable e) {
            e.printStackTrace();
        }

        try {
            Test test = new Test();
            test.test();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
